package com.ft.controller;


import com.ft.domain.CommodityType;
import com.ft.service.CommodityTypeService;
import com.ft.utils.Code;
import com.ft.utils.Result;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.Timestamp;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ft
 * @since 2022-06-01
 */
@CrossOrigin
@RestController
@RequestMapping("/commodity_type")
public class CommodityTypeController {
    @Autowired
    CommodityTypeService commodityTypeService;
    /**
     * 获取所有商品类型
     * @return
     */
    @GetMapping("")
    public Result getCommodityType(){
        List<CommodityType> commodities = commodityTypeService.getCommodities();
        return new Result(Code.GET_OK,commodities,"查询成功");
    }
    /**
     * 修改商品类型信息
     * @param commodityType 传入的商品类型对象
     * @return 返回受影响的行数
     */
    @PutMapping("")
    public Result updateCommodityType(@RequestBody CommodityType commodityType){
        commodityType.setUpdateTime(String.valueOf(new Timestamp(System.currentTimeMillis())));
        int i = commodityTypeService.updateCommodityType(commodityType);
        return new Result(Code.PUT_OK,"修改成功！");
    }
}

